﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master.master" %>

<%@ Import Namespace="DataAccess" %>
<script runat="server">
    [System.Web.Services.WebMethod]
    public static IEnumerable GetDownloadLogs()
    {
        SqlAccess sql = new SqlAccess();
        return sql.GetModelList<DownloadLog>("DownloadLog", null, null, null);
    }

    [System.Web.Services.WebMethod]
    public static void Delete(int id)
    {
        SqlAccess sql = new SqlAccess();
        sql.DeleteModel("DownloadLog", new { ID = id });
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="pagetitle" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="pagemaincontent" runat="Server">
    <style type="text/css">
        #Container table
        {
            width: 100%;
        }
        
        #Container tr.odd
        {
            background-color: #063366;
        }
        
        #Container tr.even
        {
            background-color: #131313;
        }
        
        #Container
        {
            margin-top: 10px;
            margin-bottom: 20px;
        }
        
        #Container td
        {
            padding: 6px;
        }
        #Container th[onclick]
        {
            min-width: 80px;
            cursor: pointer;
        }
    </style>
    <div id="demo1content">
        <div class="PaginationContainer">
        </div>
        <br style="clear: both;" />
        <!-- An empty div to show the actual table -->
        <div id="Container">
        </div>
        <!-- The template of the "repeater" -->
        <textarea id="template" style="display: none">
			<table>
				<tr>
					<th></th>
					<th onclick="sort('File')">File Name</th>
					<th onclick="sort('Downloaded')">Downloaded</th>
					<th onclick="sort('Transaction')">Transaction</th>
					<th></th>
				</tr>
				{#foreach $T as d}
				<tr class="{#cycle values=['odd','even']}">
					<td> {$T.d$index + 1} </td>
					<td> {$T.d.File} </td>
					<td> {$d.datetime.format($T.d.Downloaded, "MMM/dd/yyyy hh:mm")} </td>
					<td> {$T.d.Transaction} </td>
                   <td><a href="javascript:void(0)" onclick="deleting('{$T.d.ID}')">delete</a></td>
				</tr>
				{#/for}
			</table>
		</textarea>
        <!-- template end -->
        <div class="PaginationContainer">
        </div>
        <br style="clear: both;" />
    </div>
    <link rel="stylesheet" href="../css/pagination.css" />
    <script type="text/javascript" src="../jQueryClient/postback.js"></script>
    <script type="text/javascript" src="../jQueryClient/databind.js"></script>
    <script type="text/javascript" src="../jQueryClient/jTemplates.js"></script>
    <script type="text/javascript" src="../jQueryClient/pagination.js"></script>
    <script type="text/javascript" src="../jQueryClient/dataformat.js"></script>
    <script type="text/javascript" src="../jQueryClient/datejs.js"></script>
    <script type="text/javascript">
        $(function () {
            $.doPostback("GetDownloadLogs", {}, function (data) {
                $("#Container").dataBind($("#template").text(), data.d, {
                    //show pageination in .PaginationContainer
                    page_container: '.PaginationContainer',
                    empty_text: '<span style="color:Red;">No data in the data source.</span>',
                    page_size: 10,
                    page_animation: 'fadein'
                });
            });
        });

        function deleting(id) {
            $.doPostback("Delete", { id: id }, function (data) {
                $("#Container").trigger("delete", id);
            });
        }

        //sorting
        var d = 1;
        function sort(field) {
            if (field == 'Downloaded')
                $("#Container").trigger('sort', [field, d, 'datetime']);
            else
                $("#Container").trigger('sort', [field, d]);

            d *= -1;
        }
    </script>
</asp:Content>
